﻿using Asion.Dapper.SqlBuilder;
using Dapper;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using static Asion.Dapper.SqlMapperExtensions;

namespace Asion.Dapper
{
    public abstract class BaseCondition<TEntity> where TEntity : IEntity
    {

        public BaseCondition()
        {
            var info = SqlMapperExtensions.GetPropertiesCache(new PropertyIdentity(typeof(TEntity)));
            _custom_table_mappinghandle = new SimpleCustomTableMappingHandle(info);


            var name = TenantMananger.GetTenantsName<TEntity>();
            var dbtype = DapperConfiguration.connection_factory.GetDbType(name);

            _encap_sulation = EncapSulationFactory.Create(dbtype);
        }


        internal IEncapSulation _encap_sulation;

        internal ICustomTableMappingHandle _custom_table_mappinghandle;


        internal DynamicParameters DynamicParam { get; set; }





        internal void AddDynamicParam(string name, object value, System.Data.DbType dbtype, CondtionOperator oprator)
        {
            if (DynamicParam == null)
            {
                DynamicParam = new DynamicParameters();
            }
            DynamicParam.Add(name, value, dbtype);
        }

        internal void AddDynamicParam(DynamicParameters dynamic)
        {

            if (DynamicParam == null)
            {
                DynamicParam = new DynamicParameters();
            }
            DynamicParam.AddDynamicParams(dynamic);

        }

        internal void ClearDynamicParam()
        {
            if (DynamicParam != null)
            {
                DynamicParam = new DynamicParameters();
            }
        }


    }
}
